package 反射;

import java.lang.reflect.Method;

public class Test08 {
    //普通方式调用
    public  static   void   test01(){
        User user = new User();
        long  startTime=System.currentTimeMillis();
        for (int i = 0; i < 1000000000; i++) {
            user.getName();
        }
        long  endTime=System.currentTimeMillis();

        System.out.println("执行10亿次的时间"+(endTime-startTime));
    }
    public  static   void   test02() throws NoSuchMethodException {
        User user = new User();
        Class c1= user.getClass();
        Method setName = c1.getDeclaredMethod("setName", String.class);

        long  startTime=System.currentTimeMillis();
        for (int i = 0; i < 1000000000; i++) {
            user.getName();
        }
        long  endTime=System.currentTimeMillis();

        System.out.println("执行10亿次的时间"+(endTime-startTime));
    }
    public  static   void   test03() throws NoSuchMethodException {
        User user = new User();
        Class c1= user.getClass();
        Method setName = c1.getDeclaredMethod("setName", String.class);
        setName.setAccessible(true);
        long  startTime=System.currentTimeMillis();
        for (int i = 0; i < 1000000000; i++) {
            user.getName();
        }
        long  endTime=System.currentTimeMillis();

        System.out.println("执行10亿次的时间"+(endTime-startTime));
    }

    public static void main(String[] args) throws NoSuchMethodException {
        test01();
        test02();
        test03();
    }
}
